<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>登录日志管理</title>
    <link rel="stylesheet" href="/component/pear/css/pear.css"/>
</head>
<body class="pear-container">

<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">用户名称:</label>
                    <div class="layui-input-inline">
                        <input type="text" name="realName" placeholder="用户名称" class="layui-input" autocomplete="off">
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">用户账号:</label>
                    <div class="layui-input-inline">
                        <input type="text" name="userName" placeholder="用户账号" class="layui-input" autocomplete="off">
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">用户类型:</label>
                    <div class="layui-input-inline">
                        <select id="loginType" name="loginType">
                            <option value="">用户类型</option>
                            <option value="12">超级管理员</option>
                            <option value="13">系统管理员</option>
                            <option value="14">系统用户</option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">开始时间:</label>
                    <div class="layui-input-inline">
                        <input type="text" name="beginTime" placeholder="请选择开始时间" id="beginTime" readonly="readonly"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">结束时间:</label>
                    <div class="layui-input-inline">
                        <input type="text" name="endTime" placeholder="请选择结束时间" id="endTime" readonly="readonly"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">登录状态:</label>
                    <div class="layui-input-inline">
                        <select id="loginStart" name="loginStart">
                            <option value="">登录状态</option>
                            <option value="1">成功</option>
                            <option value="2">失败</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="log-query">
                        <i class="layui-icon layui-icon-search"></i>
                        查询
                    </button>
                    <button type="reset" class="pear-btn pear-btn-md">
                        <i class="layui-icon layui-icon-refresh"></i>
                        重置
                    </button>
                </div>
            </div>
        </form>
    </div>
</div>


<!--数据表格-->
<div class="layui-card">
    <div class="layui-card-body">
        <table id="log-table" lay-filter="log-table"></table>
    </div>
</div>


<script src="/component/layui/layui.js"></script>
<script src="/component/pear/pear.js"></script>
<script>
    layui.use(['table', 'form', 'jquery', 'laydate'], function () {
        let table = layui.table;
        let form = layui.form;
        let $ = layui.jquery;
        let laydate = layui.laydate;

        //渲染时间选择器
        laydate.render({
            elem: '#beginTime',
            type: 'datetime'
        });
        laydate.render({
            elem: '#endTime',
            type: 'datetime'
        });

        let cols = [
            [
                {
                    title: '日志ID',
                    field: 'id',
                    hide: true,
                    align: 'center',
                },
                {
                    title: '用户姓名',
                    field: 'realName',
                    align: 'center'
                },
                {
                    title: '登录账号',
                    field: 'userName',
                    align: 'center',
                },
                {
                    title: 'IP',
                    field: 'ip',
                    align: 'center',
                },
                {
                    title: '浏览器',
                    field: 'browser',
                    align: 'center',
                },
                {
                    title: '操作系统',
                    field: 'system',
                    align: 'center',
                },
                {
                    title: '登录状态',
                    field: 'loginStart',
                    align: 'center',
                    templet: function (d) {
                        return d.loginStart == 1 ? '<font>成功</font>' : '<font>失败</font>';
                    }
                },
                {
                    title: '用户类型',
                    field: 'loginType',
                    align: 'center',
                    templet: function (d) {
                        let str = "";
                        if (d.loginType == 12) {
                            str = "超级管理员";
                        } else if (d.loginType == 13) {
                            str = "系统管理员";
                        } else if (d.loginType == 14) {
                            str = "系统用户";
                        }
                        return '<font>' + str + '</font>';
                    }
                },
                {
                    title: '登录时间',
                    field: 'loginTime',
                    align: 'center',
                },

            ]
        ]

        var tableIns = table.render({
            elem: '#log-table',
            url: '/log/loadAllLogByPage',
            page: true,
            cols: cols,
            response: {
                statusCode: 200
            },
            done: function (res, curr, count) {
                if (res.data.length == 0 && curr != 1) {
                    tableIns.reload({
                        page: {
                            curr: (curr - 1)
                        }
                    });
                }
            },
        });


        //表格监听
        form.on('submit(log-query)', function (data) {
            table.reload('log-table', {
                where: data.field
            })
            return false;
        });

    })
</script>
</body>
</html>
